<template>
  <div>
    <el-row>
      <el-button type="primary" style="margin-bottom: 12px" @click="handleAdd">添加</el-button>
      <el-table :data="tableData" class="table-body" :header-cell-style="{background:'#F4F6F9',color:'#1D2129'}">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="orgName" label="组织名称"></el-table-column>
        <el-table-column prop="personCharge" label="负责人"></el-table-column>
        <el-table-column prop="tel" label="联系电话"></el-table-column>
        <el-table-column prop="updateDate" show-overflow-tooltip label="更新时间"></el-table-column>
        <el-table-column label="操作" width="120" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="handleEdit(scope.row.orgId)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.row.orgId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination :count="Number(count)" :current="1" @handleSizeChange="handleSizeChange"
                  @handleCurrentChange="handleCurrentChange" />
    </el-row>
    <Add ref="add" @getParentTableData="getParentTableData" />
    <Detail ref="detail" @getParentTableData="getParentTableData" />
  </div>
</template>

<script>
import Pagination from "@/components/Pagination.vue";
import Add from "./Add";
import Detail from "./Detail";
import { deleteOrgApi } from "@/api/modules/org.api";

export default {
  components: { Pagination, Add,Detail },
  props: ['tableData','count'],
  data() {
    return {
      visible: false,
      page: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  methods: {
    handleSizeChange(pageSize) {
      this.page.pageNum = pageSize
      this.$emit('getTableData',this.page)
    },
    handleCurrentChange(pageNum) {
      this.page.pageNum = pageNum
      this.$emit('getTableData',this.page)
    },
    handleAdd() {
      this.$refs.add.init()
    },
    getParentTableData(){
      this.$emit('getTableData',this.page)
    },
    handleEdit(id){
      this.$refs.detail.init(id)
    },
    async handleDelete(id){
      await deleteOrgApi(id)
      this.$message({
        message: '成功',
        type: 'success'
      });
      this.$emit('getTableData',this.page)
    }
  }
}
</script>
